package com.fhzn.auth.web.request;

import com.fhzn.auth.tools.DateTimeUtils;
import com.fhzn.commons.toolkit.exception.BuzException;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @author 老顾
 * @apiNote
 * @since 2023/12/27
 */
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class UserQueryRequest extends BaseRequest {
    private Integer id;
    private String nickname;
    private Integer status;
    private Integer userType;
    private String mobile;
    private String parentNickName;
    private Long organizationId;
    private String appCode;
    /**
     * time=1591009201000,1593601201000
     */
    private String time;
    private String startTime;
    private String endTime;

    public void initQueryTime() {
        if (StringUtils.isNotBlank(time)) {
            String[] s = time.split(",");
            String startTime = DateTimeUtils.format(new Date(Long.parseLong(s[0])));
            String endTime = DateTimeUtils.format(new Date(Long.parseLong(s[1])));
            setStartTime(startTime);
            setEndTime(endTime);
        }
    }

    public void checkParams() {
        this.checkBaseParams();
    }

    public void rewriteParams() {
        if (StringUtils.isBlank(nickname)) {
            this.setNickname(null);
        }
        if (StringUtils.isBlank(mobile)) {
            this.setMobile(null);
        }
    }

    public void checkId() {
        if (id == null) {
            throw new BuzException("id不能为空");
        }
        checkBaseParams();
    }

    /**
     * 生成发往服务端的query对象
     */
    @Override
    public Object genServiceParam() {
        throw new UnsupportedOperationException();
    }

}
